package com.example.work.check;

import com.example.work.Excel.*;

import java.util.Arrays;

/**
 * 资产类型枚举
 * 用于映射文件名中的类型字符串到对应的实体类
 */
public enum AssetTypeEnum {
    
    All("全部", AssetReportZhiwang.class),
    Comparison("对比", AssetEntity.class),

    DATABASE("数据库", DatabaseAssetXlsx.class),
    SERVER("服务器", ServerAssetXlsx.class),
    WEB("Web", WebAssetXlsx.class),
    MIDDLEWARE("中间件", MiddlewareXlsx.class),
    LOAD_BALANCER("负载均衡", LoadBalancerXlsx.class),
    OTHER_APPLICATION_SOFTWARE("其他应用软件", OtherApplicationSoftwareXlsx.class),
    OTHER("其他", OtherAssetXlsx.class),


    FIREWALL("防火墙", Firewall.class),
    SECURITY_PRODUCT("安全产品", SecurityProduct.class),
    ROUTER("路由器", Router.class),
    SUPPLY_CHAIN("供应链管理系统", SupplyChainManagementSystem.class),
    SWITCH("交换机", Switch.class);

    private final String typeName;
    private final Class<?> entityClass;
    
    AssetTypeEnum(String typeName, Class<?> entityClass) {
        this.typeName = typeName;
        this.entityClass = entityClass;
    }
    
    public String getTypeName() {
        return typeName;
    }
    
    public Class<?> getEntityClass() {
        return entityClass;
    }
    
    /**
     * 根据类型名称查找对应的枚举
     * @param typeName 类型名称（如"数据库"、"服务器"等）
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果找不到对应的类型
     */
    public static AssetTypeEnum fromTypeName(String typeName) {
        return Arrays.stream(values())
                .filter(type -> type.getTypeName().equals(typeName))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未知的资产类型: " + typeName));
    }
    
    /**
     * 根据实体类查找对应的枚举
     * @param entityClass 实体类
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果找不到对应的类型
     */
    public static AssetTypeEnum fromEntityClass(Class<?> entityClass) {
        return Arrays.stream(values())
                .filter(type -> type.getEntityClass().equals(entityClass))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未知的实体类: " + entityClass.getName()));
    }
}